package com.wwwarehouse.resource_center.fragment.createobject.creategoods;

import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.UnderlineSpan;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.wwwarehouse.common.activity.BaseCardDeskActivity;
import com.wwwarehouse.common.bean.response.CommonClass;
import com.wwwarehouse.common.custom_widget.CustomViewPagerInternal;
import com.wwwarehouse.common.custom_widget.ElasticScrollView;
import com.wwwarehouse.common.tools.LogUtils;
import com.wwwarehouse.common.tripartite_widget.viewindicator.CirclePageIndicator;
import com.wwwarehouse.resource_center.R;
import com.wwwarehouse.resource_center.adapter.rules.MyPagerAdapter;
import com.wwwarehouse.resource_center.bean.goods.GoodsSelectLabelBean;
import com.wwwarehouse.resource_center.constant.ResourceConstant;
import com.wwwarehouse.resource_center.eventbus_event.GoodsEvent;
import com.wwwarehouse.resource_center.eventbus_event.RulesEvent;
import com.wwwarehouse.resource_center.fragment.rules.TheParentFragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import de.greenrobot.event.EventBus;

/**
 * @author Joseph on 2017/9/18.
 *         <p/>
 *         选择标签
 */

public class GoodsSelectTheLabelParentFragment extends TheParentFragment implements View.OnClickListener {

    CustomViewPagerInternal viewPager;
    CustomViewPagerInternal mSearchPager;
    CirclePageIndicator pageIndicator;
    CirclePageIndicator mSearchIndicator;
    ArrayList<Fragment> fragmentList;
    ArrayList<Fragment> mSearchFragmentList;
    ElasticScrollView elasticScrollView;
    MyPagerAdapter adapter;
    MyPagerAdapter mSearchAdapter;
    List<GoodsSelectLabelBean.ListBean> tagList = new ArrayList<>();
    private Button mConfirm;
    private Button mSelected;
    private TextView mAddLabel;
    int mNum = 24;
    public static final int SELECT_LABER_BYNAME = 1;  //全部的标签
    public static final int SEARCH_LABER_BYNAME = 2;  //根据标签名模糊查找标签
    private GoodsSelectLabelBean.ListBean msg;
    private boolean isShow = true;
    private int currentPos;
    private String searchName;
    private List<GoodsSelectLabelBean.ListBean> searchSelectTag;  //记录搜索选中出来的标签
    private List<GoodsSelectLabelBean.ListBean> searchAllSelectTag;  //记录已经搜索出来的标签
    private List<GoodsSelectLabelBean.ListBean> allSelectTag;     //记录全部选择的标签
    List<GoodsSelectLabelBean.ListBean> mSelectList = new ArrayList<>();
    ArrayList<GoodsSelectLabelBean.ListBean> data; //拼卡回显的数据

    @Override
    protected int getContentId() {
        return R.layout.fragment_goods_select_the_label;
    }

    @Override
    public void setTitle() {
        if (peekFragment() instanceof GoodsSelectTheLabelParentFragment)
            mActivity.setTitle(getString(R.string.goods_select_the_label));
    }

    @Override
    protected void init(View view) {
        EventBus.getDefault().register(this);
        elasticScrollView = findView(view, R.id.elastic_scroll);
        viewPager = findView(view, R.id.task_pager);
        mSearchPager = findView(view, R.id.search_pager);
        pageIndicator = findView(view, R.id.pager_indicator);
        mSearchIndicator = findView(view, R.id.search_indicator);
        mConfirm = findView(view, R.id.confirm);
        mSelected = findView(view, R.id.selected);
        mAddLabel = findView(view, R.id.add_new_label);
        SpannableString msp = new SpannableString("新增标签");
        msp.setSpan(new UnderlineSpan(), 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        mAddLabel.setText(msp);
        elasticScrollView.setOnPullListener(new ElasticScrollView.OnPullListener() {
            @Override
            public void onDownPull() {
                if (isShow) {
                    ((BaseCardDeskActivity) mActivity).hideSortBt();
                    ((BaseCardDeskActivity) mActivity).hideFilterBt();
                    ((BaseCardDeskActivity) mActivity).showSearchTitle();
                } else {
                    ((BaseCardDeskActivity) mActivity).hideSearchTitle();
                }
                isShow = !isShow;
            }

            @Override
            public void onUpPull() {

            }
        });
    }

    @Override
    public void cancelClick() {
        if (peekFragment() instanceof GoodsSelectTheLabelParentFragment) {
            refreshPage(mSelectList);
            ((BaseCardDeskActivity) mActivity).showSearchTitle();
            ((BaseCardDeskActivity) mActivity).hideSearchInput();
            viewPager.setVisibility(View.VISIBLE);
            mAddLabel.setVisibility(View.VISIBLE);
            mSearchPager.setVisibility(View.GONE);
            if (null != mSearchFragmentList) {
                mSearchFragmentList.clear();

            }
            mSearchIndicator.setVisibility(View.GONE);
            pageIndicator.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void searchNoRealTimeClick(String text) {
        if (peekFragment() instanceof GoodsSelectTheLabelParentFragment) {
            searchName = text;
            SelectTheLabel(searchName);
        }
    }

    //搜索出来的界面
    private void SelectTheLabel(String searchName) {
        Map<String, Object> map = new HashMap();
        Map<String, Object> query = new HashMap<>();
        map.put("labelName", searchName);
        map.put("businessId", sp.getValue("businessId"));
        query.put("page", 1);
        query.put("size", mNum);
        query.put("sort", "update_time desc");
        map.put("query", query);
        httpPost(ResourceConstant.SELECT_LABER_BYNAME, map, SEARCH_LABER_BYNAME, false, "");
    }

    //获取选择的任务数据包括搜索出来的数据集合
    private List<GoodsSelectLabelBean.ListBean> getAllSelectTag() {
        List<GoodsSelectLabelBean.ListBean> selectDatas = new ArrayList<>();
        if (null != fragmentList) {
            for (int i = 0; i < fragmentList.size(); i++) {
                if (fragmentList.get(i) != null) {
                    GoodsLabelSelectLabelsFragment currentFragment = (GoodsLabelSelectLabelsFragment) fragmentList.get(i);
                    if (currentFragment.mAdapter != null) {
                        List<GoodsSelectLabelBean.ListBean> selectData = currentFragment.mAdapter.getSelectData();
                        for (int i1 = 0; i1 < selectData.size(); i1++) {
                            if (selectData.get(i1).isSelect()) {
                                selectDatas.add(selectData.get(i1));
                            }
                        }
                    }
                }
            }
        }
//        for (int i = 0; i < mSelectTasksListBean.size(); i++) {
//            LogUtils.showInfoLog("1111111111selectDatas.size()"+mSelectTasksListBean.size()+"UKID:"+mSelectTasksListBean.get(i).getLabelUkid()+"Name:"+mSelectTasksListBean.get(i).getLabelName()+"isSelect:"+mSelectTasksListBean.get(i).isSelect());
//        }
        //遍历搜索的标签集合
        if (null != mSearchFragmentList) {
            for (int i = 0; i < mSearchFragmentList.size(); i++) {
                if (mSearchFragmentList.get(i) != null) {
                    GoodsLabelSelectLabelsFragment currentFragment = (GoodsLabelSelectLabelsFragment) mSearchFragmentList.get(i);
                    if (currentFragment.mAdapter != null) {
                        List<GoodsSelectLabelBean.ListBean> mSearchData = currentFragment.mAdapter.getSelectData();
                        for (int s = 0; s < mSearchData.size(); s++) {
                            LogUtils.showInfoLog("2222222222selectData.size()" + mSearchData.size() + "UKID:" + mSearchData.get(s).getLabelUkid() + "Name:" + mSearchData.get(s).getLabelName() + "isSelect:" + mSearchData.get(s).isSelect());
                        }
                        for (int i1 = 0; i1 < mSearchData.size(); i1++) {
                            if (selectDatas.size() > 0) {
                                for (int i2 = 0; i2 < selectDatas.size(); i2++) {
                                    if (!mSearchData.get(i1).isSelect() && mSearchData.get(i1).getLabelUkid().equals(selectDatas.get(i2).getLabelUkid())) {
                                        selectDatas.add(mSearchData.get(i1));
                                    }
                                    if (!mSearchData.get(i1).isSelect() && mSearchData.get(i1).getLabelUkid().equals(selectDatas.get(i2).getLabelUkid())) {
                                        selectDatas.remove(selectDatas.get(i2));
                                    }
                                }
                            } else {
                                for (int j = 0; j < mSearchData.size(); j++) {
                                    if (mSearchData.get(j).isSelect()) {
                                        selectDatas.add(mSearchData.get(j));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        if (null != searchSelectTag) {
            selectDatas.addAll(searchSelectTag);
        }
        List<GoodsSelectLabelBean.ListBean> listBeen = removeDuplicate(selectDatas);
        return listBeen;
    }

    //刷新所有的页面
    public void refreshPage(List<GoodsSelectLabelBean.ListBean> list) {
        if (null != fragmentList) {
            for (int i = 0; i < fragmentList.size(); i++) {
                if (fragmentList.get(i) != null) {
                    GoodsLabelSelectLabelsFragment currentFragment = (GoodsLabelSelectLabelsFragment) fragmentList.get(i);
                    if (currentFragment.mAdapter != null) {
                        currentFragment.mAdapter.refreshPage(list);
                    }
                }
            }
        }
    }

    //获取已经搜索并且选中的标签
    private List<GoodsSelectLabelBean.ListBean> getSearchSelectTag() {
        List<GoodsSelectLabelBean.ListBean> selectDatas = new ArrayList<>();
        if (null != mSearchFragmentList) {
            for (int i = 0; i < mSearchFragmentList.size(); i++) {
                if (mSearchFragmentList.get(i) != null) {
                    GoodsLabelSelectLabelsFragment currentFragment = (GoodsLabelSelectLabelsFragment) mSearchFragmentList.get(i);
                    if (currentFragment.mAdapter != null) {
                        List<GoodsSelectLabelBean.ListBean> selectData = currentFragment.mAdapter.getSelectData();
                        for (int i1 = 0; i1 < selectData.size(); i1++) {
                            if (selectData.get(i1).isSelect()) {
                                selectDatas.add(selectData.get(i1));
                            }
                        }
                    }
                }
            }
        }
        return removeDuplicate(selectDatas);
    }

    //获取已经搜索的标签
    private List<GoodsSelectLabelBean.ListBean> getAllSearchSelectTag() {
        List<GoodsSelectLabelBean.ListBean> selectDatas = new ArrayList<>();
        if (null != mSearchFragmentList) {
            for (int i = 0; i < mSearchFragmentList.size(); i++) {
                if (mSearchFragmentList.get(i) != null) {
                    GoodsLabelSelectLabelsFragment currentFragment = (GoodsLabelSelectLabelsFragment) mSearchFragmentList.get(i);
                    if (currentFragment.mAdapter != null) {
                        List<GoodsSelectLabelBean.ListBean> selectData = currentFragment.mAdapter.getSelectData();
                        selectDatas.addAll(selectData);
                    }
                }
            }
        }
        return removeDuplicate(selectDatas);
    }

    //去重
    private List<GoodsSelectLabelBean.ListBean> removeDuplicate(List<GoodsSelectLabelBean.ListBean> list) {
        Set<GoodsSelectLabelBean.ListBean> set = new HashSet<>();
        List<GoodsSelectLabelBean.ListBean> newList = new ArrayList<>();
        for (Iterator<GoodsSelectLabelBean.ListBean> iter = list.iterator(); iter.hasNext(); ) {
            GoodsSelectLabelBean.ListBean element = iter.next();
            if (set.add(element))
                newList.add(element);
        }
        return newList;
    }

    @Override
    public void requestDatas() {
        mAddLabel.setOnClickListener(this);
        mSelected.setOnClickListener(this);
        mConfirm.setOnClickListener(this);
    }

    public void onEventMainThread(RulesEvent event) {
        switch (event.getMsg()) {
            case "notify":
                GoodsSelectLabelBean.ListBean bean = (GoodsSelectLabelBean.ListBean) event.getData();
                if (null != bean) {
                    LogUtils.showInfoLog("notify:" + bean.toString());
                    //可能同一个，一个是true，一个是false
                    if (!mSelectList.contains(bean)) {
                        if (mSelectList.size() > 0) {
                            for (int i = 0; i < mSelectList.size(); i++) {
                                if (mSelectList.get(i).getLabelUkid().equals(bean.getLabelUkid()) && !bean.isSelect()) {
                                    mSelectList.remove(i);
                                    break;
                                }
                                if (!mSelectList.get(i).getLabelUkid().equals(bean.getLabelUkid()) && bean.isSelect()) {
                                    mSelectList.add(bean);
                                    break;
                                }
                            }
                        } else {
                            mSelectList.add(bean);
                        }
                    } else {
                        if (!bean.isSelect()) {
                            mSelectList.remove(bean);
                        }
                    }
                }
                LogUtils.showInfoLog("notify");
                int selectTagCount = mSelectList.size();
                if (selectTagCount > 0) {
                    mConfirm.setEnabled(true);
                    mSelected.setEnabled(true);
                    mSelected.setText("已选" + selectTagCount);
                } else {
                    mConfirm.setEnabled(false);
                    mSelected.setEnabled(false);
                    mSelected.setText("已选");
                }
                break;
            case "notify-Have-Chosen":
                refreshPage(mSelectList);
                break;
        }
    }

    //新增标签通知主页面
    public void onEventMainThread(GoodsEvent event) {
        switch (event.getCode()) {
            case GoodsEvent.GOODS_ADD_LABEL:
                msg = (GoodsSelectLabelBean.ListBean) event.getData();
                msg.setSelect(true);
                LogUtils.showInfoLog("GoodsEvent:" + msg.getLabelName());

//                int count = ((GoodsLabelSelectLabelsFragment) fragmentList.get(fragmentList.size() - 1)).mAdapter.getItemCount();
//                    viewPager.setCurrentItem(fragmentList.size()-1);
//                    EventBus.getDefault().post(new GoodsEvent(GoodsEvent.GOODS_ADD_LABEL_REFRESH,msg,fragmentList.size()+""));
                if (null != ((GoodsLabelSelectLabelsFragment) fragmentList.get(fragmentList.size() - 1)).mAdapter &&
                        ((GoodsLabelSelectLabelsFragment) fragmentList.get(fragmentList.size() - 1)).mAdapter.getItemCount() == mNum) {
                    GoodsLabelSelectLabelsFragment categoryFragment = new GoodsLabelSelectLabelsFragment();
                    fragmentList.add(categoryFragment);
//                    viewPager.setOffscreenPageLimit(fragmentList.size());
                    Bundle bundle = new Bundle();
                    bundle.putInt("pos", fragmentList.size());
                    bundle.putInt("num", fragmentList.size());
                    bundle.putParcelable("data", msg);
                    categoryFragment.setArguments(bundle);
                    viewPager.setCurrentItem(fragmentList.size() - 1);
//                    categoryFragment.mAdapter.notifyDataSetChanged();
//                    adapter.notifyDataSetChanged();
//                    pageIndicator.notifyDataSetChanged();
                }

                if (null != ((GoodsLabelSelectLabelsFragment) fragmentList.get(fragmentList.size() - 1)).mAdapter &&
                        ((GoodsLabelSelectLabelsFragment) fragmentList.get(fragmentList.size() - 1)).mAdapter.getItemCount() < mNum) {
                    ((GoodsLabelSelectLabelsFragment) fragmentList.get(fragmentList.size() - 1)).mAdapter.addSelectData(msg);
                    ((GoodsLabelSelectLabelsFragment) fragmentList.get(currentPos)).mAdapter.notifyDataSetChanged();
                }
                viewPager.setCurrentItem(fragmentList.size() - 1);
                break;
            case GoodsEvent.GOODS_ADD_LABEL_NOTICE:
                if (null != msg) {
                    int num = (int) event.getData();
                    if (num == mNum) {
                        //最后一页满了
                        GoodsLabelSelectLabelsFragment categoryFragment = new GoodsLabelSelectLabelsFragment();
                        fragmentList.add(categoryFragment);
//                        viewPager.setOffscreenPageLimit(fragmentList.size());
                        Bundle bundle = new Bundle();
                        bundle.putInt("pos", fragmentList.size());
                        bundle.putInt("num", fragmentList.size());
                        bundle.putParcelableArrayList("selectedLabel", (ArrayList<? extends Parcelable>) mSelectList);
                        bundle.putParcelable("data", msg);
                        categoryFragment.setArguments(bundle);
//                        adapter.notifyDataSetChanged();
//                        pageIndicator.notifyDataSetChanged();
                        viewPager.setCurrentItem(fragmentList.size() - 1);
                    } else {
                        ((GoodsLabelSelectLabelsFragment) fragmentList.get(fragmentList.size() - 1)).mAdapter.addSelectData(msg);
                    }
                }
                break;
        }
    }

    @Override
    protected void loadDatas() {
        Bundle arguments = getArguments();
        if (null != arguments) {
            data = arguments.getParcelableArrayList("LabelList");
        }
        if (null != data) {
            mSelectList.addAll(data);
        }
        Map<String, Object> map = new HashMap();
        Map<String, Number> query = new HashMap<>();
        map.put("labelName", "");
        map.put("businessId", sp.getValue("businessId"));
        query.put("page", 1);
        query.put("size", mNum);
        map.put("query", query);
        httpPost(ResourceConstant.SELECT_LABER_BYNAME, map, SELECT_LABER_BYNAME, false, "");
//        fragmentList = new ArrayList<>();
//        for (int i = 1; i <= 8; i++) { //8 代表总共几页
//            GoodsLabelSelectLabelsFragment categoryFragment = new GoodsLabelSelectLabelsFragment();
//            fragmentList.add(categoryFragment);
//            Bundle bundle = new Bundle();
////            bundle.putParcelableArrayList("data", (ArrayList<? extends Parcelable>) taskUnits);
//            bundle.putInt("pos", i);
//            bundle.putInt("num", 8);
//            categoryFragment.setArguments(bundle);
//        }
//        adapter = new MyFragmentPagerAdapter(getChildFragmentManager(), fragmentList);
//        viewPager.setAdapter(adapter);
//        viewPager.setCurrentItem(0);
//        pageIndicator.setViewPager(viewPager, 0);
//        pageIndicator.setOnPageChangeListener(mlistener);
    }
//    private ArgbEvaluator mArgbEvaluator = new ArgbEvaluator();


    CustomViewPagerInternal.OnPageChangeListener mlistener = new CustomViewPagerInternal.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//            LogUtils.showInfoLog("OnPageChangeListener:"+"positionOffset:"+positionOffset+"--positionOffsetPixels:"+positionOffsetPixels);
//            mAddLabel.setTextColor(evaluate);
//            mAddLabel.setAlpha(positionOffset);
        }

        @Override
        public void onPageSelected(int pos) {
            currentPos = pos;
            if (null != fragmentList) {
                if (fragmentList.get(pos) != null) {
                    GoodsLabelSelectLabelsFragment currentFragment = (GoodsLabelSelectLabelsFragment) fragmentList.get(pos);
                    if (currentFragment.mAdapter != null) {
                        currentFragment.mAdapter.refreshPage(mSelectList);
                    }
                }
            }
        }

        @Override
        public void onPageScrollStateChanged(int i) {
        }
    };

    @Override
    public void onSuccess(CommonClass commonClass, int what) {
        switch (what) {
            case SELECT_LABER_BYNAME:
                if (TextUtils.equals("0", commonClass.getCode())) {
                    GoodsSelectLabelBean goodsSelectLabelBean = JSON.parseObject(commonClass.getData().toString(), GoodsSelectLabelBean.class);
                    List<GoodsSelectLabelBean.ListBean> list = goodsSelectLabelBean.getList();
                    int total = goodsSelectLabelBean.getTotal();
                    fragmentList = new ArrayList<>();
                    int count = 0;
                    if (total > mNum) {
                        if ((total - mNum) % mNum == 0) {
                            count = (total - mNum) / mNum;
                        } else {
                            count = (total - mNum) / mNum + 1; // 总共显示多少张卡片
                        }
                    } else {
                        count = 0;
                    }

                    for (int i = 0; i <= count; i++) {
                        GoodsLabelSelectLabelsFragment categoryFragment = new GoodsLabelSelectLabelsFragment();
                        Bundle bundle = new Bundle();
                        bundle.putParcelableArrayList("dataArry", (ArrayList<? extends Parcelable>) list);
                        bundle.putParcelableArrayList("selectedLabel", (ArrayList<? extends Parcelable>) mSelectList);
                        bundle.putInt("pos", i);
                        bundle.putInt("num", count);
                        categoryFragment.setArguments(bundle);
                        fragmentList.add(categoryFragment);

                    }
                    if (isAdded()) {
                        adapter = new MyPagerAdapter(getChildFragmentManager(), fragmentList);
                        viewPager.setAdapter(adapter);
//                    viewPager.setOffscreenPageLimit(fragmentList.size());
                        pageIndicator.setViewPager(viewPager, 0);
                        pageIndicator.setOnPageChangeListener(mlistener);
                    }
                }
                break;
            case SEARCH_LABER_BYNAME:
                if (TextUtils.equals("0", commonClass.getCode())) {
                    GoodsSelectLabelBean goodsSelectLabelBean = JSON.parseObject(commonClass.getData().toString(), GoodsSelectLabelBean.class);
                    List<GoodsSelectLabelBean.ListBean> list = goodsSelectLabelBean.getList();
                    int total = goodsSelectLabelBean.getTotal();
                    viewPager.setVisibility(View.GONE);
                    pageIndicator.setVisibility(View.GONE);
                    if (total <= 0) {
                        mLoadingView.setVisibility(View.VISIBLE);
                        mLoadingView.showEmptyView(true);
                        mLoadingView.setEmptyListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                mLoadingView.showProgressView(true);
                                SelectTheLabel(searchName);
                            }
                        });
                        return;
                    }
                    mAddLabel.setVisibility(View.INVISIBLE);
                    mSearchIndicator.setVisibility(View.VISIBLE);
                    mSearchPager.setVisibility(View.VISIBLE);
                    mSearchFragmentList = new ArrayList<>();
                    int count = 0;
                    if (total > mNum) {
                        if ((total - mNum) % mNum == 0) {
                            count = (total - mNum) / mNum;
                        } else {
                            count = (total - mNum) / mNum + 1; // 总共显示多少张卡片
                        }
                    } else {
                        count = 0;
                    }

                    for (int i = 0; i <= count; i++) {
                        GoodsLabelSelectLabelsFragment categoryFragment = new GoodsLabelSelectLabelsFragment();
                        Bundle bundle = new Bundle();
                        bundle.putParcelableArrayList("dataArry", (ArrayList<? extends Parcelable>) list);
                        bundle.putParcelableArrayList("selectedLabel", (ArrayList<? extends Parcelable>) mSelectList);
                        bundle.putString("labelName", searchName);
                        bundle.putInt("pos", i);
                        bundle.putInt("num", count);
                        categoryFragment.setArguments(bundle);
                        mSearchFragmentList.add(categoryFragment);

                    }
                    if (isAdded()) {
                        mSearchAdapter = new MyPagerAdapter(getChildFragmentManager(), mSearchFragmentList);
                        mSearchPager.setAdapter(mSearchAdapter);
//                    viewPager.setOffscreenPageLimit(fragmentList.size());
                        mSearchIndicator.setViewPager(mSearchPager, 0);
//                    pageIndicator.setOnPageChangeListener(mlistener);
                    }
                }
                break;
        }

    }

    @Override
    public void onReLoad(int code) {
        loadDatas();
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.confirm) {//确认
            EventBus.getDefault().post(new GoodsEvent(GoodsEvent.GOODS_LABEL_SELECT_NOTICE, mSelectList, "GOODS_LABEL_SELECT"));
            popFragment();

        } else if (i == R.id.selected) {
            GoodsLabelHaveChosenSelectParentFragment selectParentFragment = new GoodsLabelHaveChosenSelectParentFragment();
            Bundle bundlee = new Bundle();
            bundlee.putParcelableArrayList("mSelectList", (ArrayList<? extends Parcelable>) mSelectList);
            selectParentFragment.setArguments(bundlee);
            pushFragment(selectParentFragment);

        } else if (i == R.id.add_new_label) {
            pushFragment(new GoodsLabelAddaFragment());


        }
    }
}
